package com.lotter.model.caipiao;

import java.math.BigDecimal;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lotter.common.enumobject.CashStatusEnum;
import com.lotter.common.enumobject.GoalEnum;
import com.lotter.common.enumobject.HalfCourtEnum;
import com.lotter.common.enumobject.IswinningEnum;
import com.lotter.common.enumobject.ScoreEnum;
import com.lotter.common.enumobject.ShengpingFuEnum;
import com.lotter.common.exception.LotterCusException;

public class CashRecord {
	
    private Long mid;

    private String id;

    private String match_num;

    private String phase;

    private String official_date;

    private String create_at;

    private String time_endsale;

    private String match_date;

    private String match_name;

    private String official_num;

    private String home_team;

    private String away_team;

    private String first_half;

    private String final_score;

    private String handicap;

    private String weekday;

    private String current_spf;

    private String current_rqspf;

    private String current_bqc;

    private String current_jqs;

    private String current_bf;

    //	STOP(0, "中断"),DELAY(1, "延期"),NOTCONFIRM(2, "无法确认"), FINISH(3, "结束");
    private Integer status;
    
    //未执行  执行
    private Integer execute;
    

    public Long getMid() {
        return mid;
    }

    public void setMid(Long mid) {
        this.mid = mid;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id == null ? null : id.trim();
    }

  

    public String getMatch_num() {
		return match_num;
	}

	public void setMatch_num(String match_num) {
		this.match_num = match_num;
	}

	public String getPhase() {
		return phase;
	}

	public void setPhase(String phase) {
		this.phase = phase;
	}

	public String getOfficial_date() {
		return official_date;
	}

	public void setOfficial_date(String official_date) {
		this.official_date = official_date;
	}

	public String getCreate_at() {
		return create_at;
	}

	public void setCreate_at(String create_at) {
		this.create_at = create_at;
	}

	public String getTime_endsale() {
		return time_endsale;
	}

	public void setTime_endsale(String time_endsale) {
		this.time_endsale = time_endsale;
	}

	public String getMatch_date() {
		return match_date;
	}

	public void setMatch_date(String match_date) {
		this.match_date = match_date;
	}

	public String getMatch_name() {
		return match_name;
	}

	public void setMatch_name(String match_name) {
		this.match_name = match_name;
	}

	public String getOfficial_num() {
		return official_num;
	}

	public void setOfficial_num(String official_num) {
		this.official_num = official_num;
	}

	public String getHome_team() {
		return home_team;
	}

	public void setHome_team(String home_team) {
		this.home_team = home_team;
	}

	public String getAway_team() {
		return away_team;
	}

	public void setAway_team(String away_team) {
		this.away_team = away_team;
	}

	public String getFirst_half() {
		return first_half;
	}

	public void setFirst_half(String first_half) {
		this.first_half = first_half;
	}

	public String getFinal_score() {
		return final_score;
	}

	public void setFinal_score(String final_score) {
		this.final_score = final_score;
	}

	public String getHandicap() {
		return handicap;
	}

	public void setHandicap(String handicap) {
		this.handicap = handicap;
	}

	public String getWeekday() {
		return weekday;
	}

	public void setWeekday(String weekday) {
		this.weekday = weekday;
	}

	public String getCurrent_spf() {
		return current_spf;
	}

	public void setCurrent_spf(String current_spf) {
		this.current_spf = current_spf;
	}

	public String getCurrent_rqspf() {
		return current_rqspf;
	}

	public void setCurrent_rqspf(String current_rqspf) {
		this.current_rqspf = current_rqspf;
	}

	public String getCurrent_bqc() {
		return current_bqc;
	}

	public void setCurrent_bqc(String current_bqc) {
		this.current_bqc = current_bqc;
	}

	public String getCurrent_jqs() {
		return current_jqs;
	}

	public void setCurrent_jqs(String current_jqs) {
		this.current_jqs = current_jqs;
	}

	public String getCurrent_bf() {
		return current_bf;
	}

	public void setCurrent_bf(String current_bf) {
		this.current_bf = current_bf;
	}

	public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

	public Integer getExecute() {
		return execute;
	}

	public void setExecute(Integer execute) {
		this.execute = execute;
	}

    

	//判断是否中奖  胜平负
	public int judgeWinOrLose(Integer ptype ,Integer itemtype) throws LotterCusException{
		if(this.status == CashStatusEnum.STOP.getCode()){
			return IswinningEnum.ALREADY_WINNING.getCode();
		}
		String  final_score =  this.getFinal_score();
		Integer handicap = Integer.parseInt(this.handicap);
		Integer code = 0 ;
		switch (ptype) {
		case 0://胜平负
			code = ShengpingFuEnum.judgeCode(final_score);
			break;
		case 1: //让球胜平负
		    code = ShengpingFuEnum.judgeCode(final_score,handicap);
			break;
		case 2://比分
		    code = ScoreEnum.judgeCode(final_score);
			break;
		case 3://总进球
		    code =GoalEnum.judgeCode(final_score);
			break;
		case 4://半场
		    code =HalfCourtEnum.judgeCode(final_score,first_half);
			break;
		default:
			break;
		}
		if(code.equals(itemtype)){
			return  IswinningEnum.ALREADY_WINNING.getCode();
		}else{
			return  IswinningEnum.NOT_WINNING.getCode();
		}
	}

	
	//获取赔率
	public BigDecimal getActualOdds(Integer ptype,Integer itemtype) throws LotterCusException{
		if(this.status == CashStatusEnum.STOP.getCode()){
			return BigDecimal.ONE;
		}
		JSONObject jst = null ;
		switch (ptype) {
		case 0://胜平负
			  jst =  JSON.parseObject(this.current_spf);
			break;
		case 1: //让球胜平负
			  jst =  JSON.parseObject(this.current_rqspf);
			break;
		case 2://比分
			  jst =  JSON.parseObject(this.current_bf);
			break;
		case 3://总进球
			 jst =  JSON.parseObject(this.current_jqs);
			break;
		case 4://半场
			jst =  JSON.parseObject(this.current_bqc);
			break;
		default:
			break;
		} 
		BigDecimal bigde = jst.getBigDecimal(itemtype.toString());
		return bigde ;
	}
    
}